<%-- 
    Document   : chatpage
    Created on : Apr 9, 2011, 7:51:50 AM
    Author     : Setia_Negara
--%>

<%@page import="logic.Main"%>
<%@page import="java.util.ArrayList"%>
<%@page import="classes.User"%>
<%@page import="classes.Message"%>
<%@page import="classes.Room"%>
<%@page import="classes.Category"%>
<%@page import="database.database"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
            database db = new database();
            User Userlogin = new User();
            if (session == null) {
                response.sendRedirect("index.jsp");
            }
            else {
                Userlogin = ((User)session.getAttribute("user"));
            }
            if (Userlogin.privilege.equals("admin") || Userlogin.privilege == "user") {
                response.sendRedirect("admin.jsp");
            }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="style.css" rel="stylesheet" type="text/css" />
        <script src="javascript/ajax.js" type="text/javascript"></script>
        <script src="javascript/basic.js" type="text/javascript"></script>
        <script src="javascript/chat.js" type="text/javascript"></script>
        <script src="home.js" type="text/javascript"></script>
        <title>chatOK</title>
    </head>
    <body onload="receiveChat(); loadRoom();">
        <div class="header">
            <div class="wrapper">
                <div class="logo">
                    <a href="chatpage.jsp"><img height="65px" alt="logo"  src="images/logo.png" /></a>
                </div>
                <div class="user">
                    Welcome, <a href="admin.jsp">
                        <%
                                    out.print(Userlogin.nama);
                        %>
                    </a>
                    &nbsp;
                    <a href="logout.jsp">
                        <button class="tombol">Logout</button>
                    </a>
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="main">
            <div class="wrapper">
                <div class="tabs">
                    <ul>
                        <!--    <li class="selected"><a href="#">Room</a></li>
                                <li><a href="#">User1</a></li>
                                <li><a href="#">User1</a></li>
                        -->
                        <div id="chattab_container">
                            <div class="chattab_active" id="chattab_room_home">
                                <span class="chat_name" onclick="showChat(this.parentNode)">home</span>
                                <input type="hidden" name="type" value="room">
                                <input type="hidden" name="name" value="home">
                            </div>
                        </div>
                    </ul>
                </div>
                <div class="clear">
                </div>
                <div class="chatpanel">
                    <div class="wrapperpanel">
                        <!--<input type="button" onclick="loadDummy();" value="Generate"/>-->
                        <div id="chatbox_container">
                            <div class="chatbox_active" id="chatbox_room_home">
                                <div class="chat_message"></div>
                                <div class="chat_input">
                                    <input type="text" onkeypress="chatInputHandler(event,this)">
                                    <input type="hidden" name="type" value="room">
                                    <input type="hidden" name="name" value="home">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="roompanel">
                    <div class="wrapperpanel">
                        <div class="titlepanel">
                            room
                        </div>
                        <div class="roomswrapper">
                            <div class="categorylist" id="categorylist">
                                <div class="ajaxroom" id="ajaxroom">
                                </div>
                                <br /><br />
                                <center><button class="tombol" onclick="loadRoom()">Refresh</button></center>
                                <%
                                    
                                %>
                            </div>

                            <!--    load innerhtml with ajax
                                    onecategory can contain both sub and room list
                                    onesub can contain rommlist
                            -->

                        </div>
                    </div>
                </div>
                <div class="friendpanel">
                    <div class="wrapperpanel">
                        <div class="titlepanel">
                            friends
                        </div>
                        <div class="friendswrapper">
                            <%

                                        ArrayList<String> arrayfriend = db.getFriends(Userlogin.username);
                                        System.out.println("query here\n");

                                        if (arrayfriend != null) {
                                            for (int i = 0; i < arrayfriend.size(); ++i) {
                                                out.println("<div class=\"onefriend\" onclick=\"chatClick(\'"+arrayfriend.get(i)+"\');\">");
                                                out.println(arrayfriend.get(i));
                                                out.println("</div>");
                                                System.out.println("alamak\n");
                                            }

                                        } else {
                                            System.out.println("bye");
                                        }

                            %>
                            <div class="daftaruser">
                                <%
                                    
                                %>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="footer">
            <div class="wrapper">
                Copyright &copy; 2011. ChatOK. Tugas Besar 4 Progin<br/>
                Setia Negara B. Tjaru | Ismail Sunny | Arifin Luthfi Putranto
            </div>
        </div>
    </body>
</html>
